package com.sky.verify;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckUsernameServlet extends HttpServlet{

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	        response.setContentType("text/html;charset=utf-8");
			//校验邮箱ajax(1.邮箱是否为空, 2.邮箱格式是否正确，,3.邮箱是否已经被注册)
			//1.获取请求参数
			String username = request.getParameter("username");
			System.out.println("==username="+username);
			//2.业务逻辑处理
			String result="";
			//2.1.用户名是否为空,
			if("".equals(username)||null==username){
				result="用户名不能为空";
			}else if(!username.matches("^\\S{6,}$")){
				//2.2 用户名长度，使用正则表达式
				result="用户名过短，至少六位";
			 }else {
				//2.3.用户名是否已经被注册
				result="OK";			 
			 }
			//3.处理结果，响应给页面
			response.getWriter().write(result);
		}

		public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			doGet(request, response);
		}

}
